<template>
  <div class="app-container">
    <!-- 查询 -->
    <tl-list-search ref="search" :query-param="queryParam" @search="doQuery" :isDisplayDefaultSearch="false" :isDisplaySearch="false" v-if="isHeaderDisplay">
      <template slot="search">
        <el-form-item prop="code">
          <label>项目</label>
          <el-input v-model="queryParam.qry_projectname" :disabled="true" class="tl-ref-selector" style="width:180px" @change="changeprojectname">
            <el-button slot="append" type="primary" icon="el-icon-search" @click="openPmProjectRefDialog"></el-button>
          </el-input>
        </el-form-item>
        <el-form-item>
          <label>收据客户</label>
          <el-input v-model="queryParam.qry_customername" style="width:120px" @change="changecustomername"></el-input>
        </el-form-item>
        <el-form-item>
          <label>收据号码</label>
          <el-input v-model="queryParam.qry_receiptcode" style="width:120px" @change="changereceiptcode"></el-input>
        </el-form-item>
        <el-form-item>
          <label>快递单号</label>
          <el-input v-model="queryParam.qry_couriernumber" style="width:120px" @change="changecouriernumber"></el-input>
        </el-form-item>
        <el-form-item>
          <label>收件人</label>
          <el-input v-model="queryParam.qry_receiver" style="width:80px" @change="changereceiver"></el-input>
        </el-form-item>
        <!-- <el-form-item>
                    <label>收据日期</label>
                    <el-date-picker v-model="queryParam.qry_receiptdateStart" type="date" style="width:140px" value-format="yyyy-MM-dd" />至
                    <el-date-picker v-model="queryParam.qry_receiptdateEnd" type="date" style="width:140px" value-format="yyyy-MM-dd" />
                </el-form-item> -->
        <el-form-item>
          <label>收款状态</label>
          <el-select v-model="queryParam.qry_returnmoney" clearable style="width:120px" @change="changereturnmoney">
            <el-option v-for="item in codeModel.returnmoneytypeList" :key="item.code" :label="item.name" :value="item.code" clearable />
          </el-select>
        </el-form-item>
        <el-button class="filter-item" type="primary" icon="el-icon-search" @click="doQuery">搜索</el-button>
        <el-button class="filter-item" type="primary" icon="el-icon-refresh-right" @click="resetQueryParam" :disabled="isreset">重置</el-button>
      </template>
    </tl-list-search>
    <!-- 工具栏 -->
    <tl-list-toolbar ref="toolbar" @add="openAddDialog('editForm')" :isDisplayAdd="false" @exportExcel="doExportExcel" :isDisplayDeleteBatch="false" @deleteBatch="doDeleteBatch" @refresh="doRefresh" @columnCustomize="doColumnCustomize" @displaySearch="doDisplaySearch" :disableDeleteBatch="selectedRowKeys.length <= 0">
      <template slot="left-btn">
        <el-col :span="6" align="right" :push="2" style="position:absolute;left:80px;bottom:9px;">
          <el-alert title="默认导出非作废单据。" type="warning" :closable="false" show-icon></el-alert>
        </el-col>
      </template>
    </tl-list-toolbar>
    <div>
      <!-- 列表选择 -->
      <div class="table-alert-div" ref="selector">
        <el-alert type="success" :closable="false" class="tl-table-alert-info" effect="light">
          <template slot="title">
            已选择&nbsp;<a class="tl-table-alert-info-a1">{{ selectedRowKeys.length }}</a>项&nbsp;&nbsp;
            <a class="tl-table-alert-info-a2" @click="doClearSelected">全部清空</a>
          </template>
        </el-alert>
      </div>
      <!--表格渲染-->
      <el-table class="tl-table" ref="mainTable" :height="tableHeight" resizable-key="tableHeight" :resizable-refs="tableResizeRefs" v-loading="loading" :data="datas" @selection-change="doSelectChange" @sort-change="doSortChange" @row-dblclick="doRowDbClick" row-key="id" border fit :row-class-name="doChangeRowClassName">
        <!-- <el-table-column type="selection" width="55px" fixed="left" :selectable="doDisableCheckBox"></el-table-column> -->
        <el-table-column type="index" label="序号" width="55px" align="center"></el-table-column>
        <el-table-column prop="projectcode" label="项目号" width="130px" sortable="projectcode" sort-by="projectcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="projectname" label="项目" width="220px" sortable="projectid" sort-by="projectid" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <!-- <el-table-column prop="province" label="省份" width="120px" sortable="province" sort-by="province" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <el-table-column prop="provincetop" label="省份" width="200px" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispownerarea" label="所属区域" width="120px" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="username" label="申请人" width="80px" sortable="custom" sort-by="username" align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="customername" label="客户名称" width="200px" sortable="custom" sort-by="customername" align="left" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="receiptcode" label="收据号码" width="120px" sortable="custom" sort-by="receiptcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="receiptmoney" label="收据金额" width="130px" sortable="custom" sort-by="receiptmoney" align="right" header-align="center" :formatter="moneyFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="returnmoney" label="回款金额" width="120px" sortable="custom" sort-by="returnmoney" align="right" header-align="center" :formatter="moneyFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="noretrunmoney" label="未回款金额" width="120px" sortable="noretrunmoney" sort-by="noretrunmoney" align="right" header-align="center" :formatter="moneyFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="receiptdate" label="收据日期" width="100px" sortable="custom" sort-by="receiptdate" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="days" label="开具天数" width="100px" sortable="days" sort-by="days" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="receiver" label="收件人" width="100px" sortable="custom" sort-by="receiver" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="couriernumber" label="物流单号" width="150px" sortable="custom" sort-by="couriernumber" align="right" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="maildate" label="寄出日期" width="100px" sortable="custom" sort-by="maildate" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="receiptorgname" label="收据开具组织" width="200px" sortable="custom" sort-by="receiptorgname" align="left" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="iscancel" label="是否作废" width="100px" sortable="custom" sort-by="iscancel" align="center" header-align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.iscancel === 1" type="danger">是</el-tag>
            <el-tag v-else type="success">否</el-tag>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="dispcategory" label="业务类型" width="100px" sortable="custom" sort-by="category" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="iscancel" label="是否作废" width="100px" sortable="custom" sort-by="iscancel" align="center" header-align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.iscancel === 1" type="danger">是</el-tag>
            <el-tag v-else type="success">否</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="dispreceiptdatetype" label="收据日期类型" width="150px" sortable="custom" sort-by="receiptdatetype" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="actualreceiptdate" label="实际收据日期" width="150px" sortable="custom" sort-by="actualreceiptdate" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="demand" label="收据填写要求" width="200px" sortable="custom" sort-by="demand" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="explain" label="收据说明" width="200px" sortable="custom" sort-by="explain" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="receiptorgcode" label="收据开具组织编码" width="150px" sortable="custom" sort-by="receiptorgcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="receiptdeptname" label="收据所属部门" width="200px" sortable="custom" sort-by="receiptdeptname" align="left" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="receiptdeptcode" label="收据所属部门编码" width="150px" sortable="custom" sort-by="receiptdeptcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="companyname" label="企业名称" width="200px" sortable="custom" sort-by="companyname" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="companyaddress" label="企业地址" width="200px" sortable="custom" sort-by="companyaddress" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="mailaddress" label="邮寄地址" width="200px" sortable="custom" sort-by="mailaddress" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="receivertel" label="收件人电话" width="150px" sortable="custom" sort-by="receivertel" align="right" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispreceivertype" label="收件人性质" width="150px" sortable="custom" sort-by="receivertype" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispcourier" label="快递方式" width="150px" sortable="custom" sort-by="courier" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispisreceiptreturn" label="签收单是否返回" width="150px" sortable="custom" sort-by="isreceiptreturn" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="oldreceiptdate" label="原收据日期" width="150px" sortable="custom" sort-by="oldreceiptdate" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="oldexpressno" label="原收据邮寄单号" width="150px" sortable="custom" sort-by="oldexpressno" align="right" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="oldreceiptcode" label="原收据号" width="150px" sortable="custom" sort-by="oldreceiptcode" align="right" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="oldcustomer" label="原客户名称" width="200px" sortable="custom" sort-by="oldcustomer" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="oldreceiptmoney" label="原收据金额" width="150px" sortable="custom" sort-by="oldreceiptmoney" align="right" header-align="center" :formatter="moneyFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="rereceiptreason" label="重开原因" width="200px" sortable="custom" sort-by="rereceiptreason" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="cancelreason" label="作废原因" width="200px" sortable="custom" sort-by="cancelreason" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="customerid" label="客户id" width="150px" sortable="custom" sort-by="customerid" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="latestphase" label="最新阶段" width="100px" sortable="custom" sort-by="latestphase" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispstate" label="状态" width="80px" sortable="custom" sort-by="state" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="orgname" label="申请公司" width="200px" sortable="custom" sort-by="orgname" align="left" :show-overflow-tooltip="true"></el-table-column>
                <el-table-column prop="orgcode" label="申请公司编码" width="120px" sortable="custom" sort-by="orgcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="deptname" label="申请部门" width="200px" sortable="custom" sort-by="deptname" align="left" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="deptcode" label="申请部门编码" width="120px" sortable="custom" sort-by="deptcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="usercode" label="申请人工号" width="100px" sortable="custom" sort-by="usercode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="docdate" label="单据日期" width="100px" sortable="custom" sort-by="docdate" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="submitdate" label="提交时间" width="200px" sortable="custom" sort-by="submitdate" align="center" header-align="center" :formatter="dateTimeFormat" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="docno" label="单据编号" width="120px" sortable="custom" sort-by="docno" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispflowid" label="审批流程" width="120px" sortable="custom" sort-by="flowid" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="description" label="备注" min-width="200px" align="left" header-align="left" :show-overflow-tooltip="true"></el-table-column> -->
      </el-table>
      <!-- 列表分页 -->
      <el-row class="pagebar" ref="pager">
        <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
      </el-row>
      <tl-edit ref="editForm" @refresh="doRefresh"></tl-edit>
      <tl-pm-project-ref ref="pmProjectRef" @confirm="getPmProjectRefData" :isSingleSelect="true"></tl-pm-project-ref>
    </div>
  </div>
</template>

<script>
/** mixins */
import {
  mixin_list
} from '@tapui/mixins/mixin_list'
/** 子组件 */
import tlEdit from './statisticsEdit'
import tlPmProjectRef from "@/views/ProjectManage/pmProject/refList"

/** 工具类 */
import {
  getAction,
  putAction,
  postAction,
  deleteAction
} from '@tapui/utils/http'
import {
  rmbFormat
} from "../../../utils/calculation"
import {
  validateNull
} from '@tapui/utils/validate'
export default {
  name: 'pmReceiptApplyStatistics',
  mixins: [mixin_list],
  components: {
    tlEdit,
    tlPmProjectRef
  },
  data() {
    return {
      description: '项目收据申请-列表查询',
      urlPrefix: '/pm/receiptApply/',
      url: {
        queryCodeList: '/pm/receiptApply/dataCodeList',
        listStatistics: '/pm/receiptApply/listStatistics'
      },
      // 排序参数
      sorterInfo: {
        sidx: 'pmreceiptApply.createon',
        sord: 'desc'
      },
      isreset: false
    }
  },
  methods: {
    changeprojectname() {
      if (JSON.stringify(this.queryParam) !== '{}' && this.queryParam.qry_projectname !== '') {
        this.isreset = false
      } else {
        this.isreset = true
      }
    },
    changecustomername() {
      if (JSON.stringify(this.queryParam) !== '{}' && this.queryParam.qry_customername !== '') {
        this.isreset = false
      } else {
        this.isreset = true
      }
    },
    changereceiptcode() {
      if (JSON.stringify(this.queryParam) !== '{}' && this.queryParam.qry_receiptcode !== '') {
        this.isreset = false
      } else {
        this.isreset = true
      }
    },
    changecouriernumber() {
      if (JSON.stringify(this.queryParam) !== '{}' && this.queryParam.qry_couriernumber !== '') {
        this.isreset = false
      } else {
        this.isreset = true
      }
    },
    changereceiver() {
      if (JSON.stringify(this.queryParam) !== '{}' && this.queryParam.qry_receiver !== '') {
        this.isreset = false
      } else {
        this.isreset = true
      }
    },
    changereturnmoney() {
      if (JSON.stringify(this.queryParam) !== '{}' && this.queryParam.qry_returnmoney !== '') {
        this.isreset = false
      } else {
        this.isreset = true
      }
    },
    // 禁用表格前面的选择
    doDisableCheckBox(row, index) {
      if (row.state !== 0 && row.state !== 2) {
        return false
      } else {
        return true
      }
    },
    // 崔倩需求，发票开具部门只显示二级部门
    formateSecondDeptName(deptname) {
      const deptNameArr = deptname.deptname.split('\\')
      if (deptNameArr[1]) {
        deptNameArr[1] = deptNameArr[1].replace("营销服务中心", '')
      }
      return deptNameArr[1] ? deptNameArr[1] : deptname.deptname
    },
    afterLoadData() {
      this.isreset = false
      if (typeof this.queryParam.qry_projectname === 'undefined' && typeof this.queryParam.qry_customername === 'undefined' &&
        typeof this.queryParam.qry_receiptcode === 'undefined' && typeof this.queryParam.qry_couriernumber === 'undefined' &&
        typeof this.queryParam.qry_receiver === 'undefined' && typeof this.queryParam.qry_returnmoney === 'undefined') {
        this.isreset = true
      }
    },
    /** 列表数据加载开始 */
    loadData(paramMap) {
      if (!this.url.listStatistics) {
        this.$tap.alert('请设置list地址!', 'warning')
        return
      }
      // 得到加载分页
      if (validateNull(paramMap) === false && Object.keys(paramMap).indexOf('currentPage') > -1) {
        this.pageInfo.currentPage = paramMap['currentPage']
      }
      if (!this.beforeLoadData()) return
      // 查询条件
      var params = this.getQueryParams()
      // 数据查询
      this.loading = true
      getAction(this.url.listStatistics, params)
        .then(res => {
          if (res.success) {
            this.datas = res.result.dataList
            this.pageInfo.totalCount = res.result.totalCount
            // 初始化自定义列
            this.$refs.toolbar.doInitTableColumn()
          } else {
            this.$tap.alert(res.message, 'warning')
          }
          this.afterLoadData()
          this.loading = false
        })
        .catch(err => {
          this.loading = false
        })
    },
    /** 打开项目参照 */
    openPmProjectRefDialog() {
      this.$refs.pmProjectRef.visible = true
    },
    /** 获取项目参数数据 */
    getPmProjectRefData(selectionRow, selectKey, selectionValue) {
      const {
        id,
        name
      } = selectionRow
      this.$set(this.queryParam, "qry_projectid", id)
      this.$set(this.queryParam, "qry_projectname", name)
    },
    resetQueryParam() {
      this.queryParam = {}
      this.changeprojectname()
      this.changecustomername()
      this.changereceiptcode()
      this.changecouriernumber()
      this.changereceiver()
      this.changereturnmoney()
    },
    /** 表格双击事件 */
    doRowDbClick(row, column, event) {
      this.openViewDialog('editForm', row.id)
    },
    moneyFormat(row, column, cellValue, index) {
      return rmbFormat(row[column.property])
    }
  }
}

</script>

<style scoped></style>
